

#!/usr/bin/env Python
# -*- coding: utf-8 -*-

"""
使用requests请求代理服务器
请求http和https网页均适用
"""

import requests

def get_ip_poll(num=2):
    return [get_ip_requests() for i in range(num)]


def get_ip_requests():
    # 提取代理API接口，获取1个代理IP
    api_url = "https://dps.kdlapi.com/api/getdps/?secret_id=otpgszz52nrzd1qbfr7b&signature=5r5nea9e7i339t9qkto03c22swqiczf4&num=1&sep=1"

    # 获取API接口返回的代理IP
    proxy_ip = requests.get(api_url).text

    # 用户名密码认证(私密代理/独享代理)
    username = "d4751205752"
    password = "l30bqgiw"
    proxies = {
        "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip},
        "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": proxy_ip}
    }
    print(proxies)
    # {'http': 'http://d4751205752:l30bqgiw@144.48.212.142:16378/', 'https': 'http://d4751205752:l30bqgiw@144.48.212.142:16378/'}
    return proxies